package com.yijianonghu.util.exceptionhandler;

import org.slf4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.yijianonghu.util.result.MessageCode;
import com.yijianonghu.util.result.Result;

@Component
public class ControllerExceptionHandler {

	public void handleException(Logger logger, String logMessage, Result result, MessageCode errorCode, Throwable e){
		if(logger!=null){
			logger.error(logMessage,e);
		}
		if(result!=null){
			result.setError_code(errorCode.getError_code());
			result.setMessage(errorCode.getDescription());
			result.setSuccess(false);
		}
	}
}
